package com.infoholdcity.common.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.infoholdcity.common.entity.QueryConditionsData;
import com.infoholdcity.common.service.QueryConditionsDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 查询条件数据表 前端控制器
 * </p>
 *
 * @author jinshihui
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/query-conditions-data")
public class QueryConditionsDataController {


    @Autowired
    private QueryConditionsDataService queryConditionsDataService;

    @GetMapping(value = "/")
    public ResponseEntity<Page<QueryConditionsData>> list(@RequestParam(required = false) Integer current, @RequestParam(required = false) Integer pageSize) {
        if (current == null) {
            current = 1;
        }
        if (pageSize == null) {
            pageSize = 10;
        }
        Page<QueryConditionsData> aPage = queryConditionsDataService.page(new Page<>(current, pageSize));
        return new ResponseEntity<>(aPage, HttpStatus.OK);
    }

    @GetMapping(value = "/{id}")
    public ResponseEntity<QueryConditionsData> getById(@PathVariable("id") String id) {
        return new ResponseEntity<>(queryConditionsDataService.getById(id), HttpStatus.OK);
    }

    @PostMapping(value = "/create")
    public ResponseEntity<Object> create(@RequestBody QueryConditionsData params) {
        queryConditionsDataService.save(params);
        return new ResponseEntity<>("created successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/delete/{id}")
    public ResponseEntity<Object> delete(@PathVariable("id") String id) {
        queryConditionsDataService.removeById(id);
        return new ResponseEntity<>("deleted successfully", HttpStatus.OK);
    }

    @PostMapping(value = "/update")
    public ResponseEntity<Object> update(@RequestBody QueryConditionsData params) {
        queryConditionsDataService.updateById(params);
        return new ResponseEntity<>("updated successfully", HttpStatus.OK);
    }
}
